package com.cn.hotel.servlet.front.news;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.CompanyInformationModel;
import com.cn.hotel.model.NavModel;
import com.cn.hotel.model.NewsModel;
import com.cn.hotel.model.NewsTypeModel;
import com.cn.hotel.service.ICompanyInformationService;
import com.cn.hotel.service.INavService;
import com.cn.hotel.service.INewsService;
import com.cn.hotel.service.impl.CompanyInformationServiceImpl;
import com.cn.hotel.service.impl.NavServiceImpl;
import com.cn.hotel.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/getNewsList")
public class NewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        //新闻列表获取
        /***
         * aa是类型id，bb是页码
         */
        String aa = req.getParameter("id");
        String bb = req.getParameter("page");
        Integer temp = aa==null||"".equals(aa)?0:Integer.parseInt(aa);
        Integer pageNumber =bb== null||"".equals(bb)?1:Integer.parseInt(bb);
        Map<String,Integer> map = new HashMap<>();
        map.put("temp",temp);
        map.put("pageNumber",pageNumber);
        INewsService iNewsService = new NewsServiceImpl();
        List<NewsModel> list = iNewsService.getNewsModelList(map);
        int number = iNewsService.getNumber(temp);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list",list);
        jsonObject.put("number",number);
        resp.getWriter().println(jsonObject);
    }
}
